package cn.itsource.pethome.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Author:R
 * @Date:2023/1/31 19:46
 * Description 微信相关配置
 */
@Component
public class WeChatConfig {
    @Value("${wx.appid}")
    private String appid;
    @Value("${wx.secret}")
    private String secret;
    //获取令牌的地址
    private String access_token  = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
    //获取用户信息的地址
    private String userinfo  = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESSTOKEN&openid=OPENID";

    //返回完整的获取令牌的路径
    public String getAccessToken(String code){
        return access_token.replace("APPID",appid)
                .replace("SECRET",secret)
                .replace("CODE",code);
    }

    //返回完整的获取用户信息的路径
    public String getUserinfo(String accessToken,String openid){
        return userinfo.replace("ACCESSTOKEN",accessToken)
                .replace("OPENID",openid);
    }
}
